package edu.cuit.svsp.service.impl;

import edu.cuit.svsp.entity.Danmu;
import edu.cuit.svsp.entity.UserLevel;
import edu.cuit.svsp.mapper.DanmuMapper;
import edu.cuit.svsp.mapper.UserLevelMapper;
import edu.cuit.svsp.service.DanmuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @className: DanmuServiceImpl
 * @author: pjy
 * @description: 弹幕服务实现类
 * @date: 2024/7/6
 */
@Slf4j
@Service
public class DanmuServiceImpl implements DanmuService {
    @Resource
    private DanmuMapper danmuMapper;
    @Resource
    private UserLevelMapper userLevelMapper;
    @Override
    public Danmu add(Danmu danmu) {
        // 获取用户等级
        UserLevel level = userLevelMapper.findByUid(danmu.getUid());
        danmu.setMode(level.getMode());
        danmu.setColor(level.getColor());
        danmu.setDuration(level.getDuration());
        danmuMapper.add(danmu);
        return danmu;
    }

    @Override
    public List<Danmu> findByVid(Integer vid) {
        return danmuMapper.findByVid(vid);
    }
}
